<template>
	<view>
		<view class="wrapper">
			 <view class="company">
				<text class="company-txt">选择物流</text>
				<picker mode="selector" @change="bindRegionChange" :range="company" :range-key="'kd_name'">
					<view class="picker-box">      
						<view class="picker">{{company[index].kd_name}}</view>
						<image class="picker-icon" src="/static/images/arrow-bottom.png"></image>
					</view>
				</picker>
			 </view>
			<view class="company">
				<text class="company-txt">物流单号</text>
				<input class @input="inputNo" placeholder="请填写物流单号"></input>
			</view>
			<view class="btn" @tap="commit">提交</view>
		</view>
	</view>
</template>

<script>
// pages/serviceLogistic/serviceLogistic.js
const app = getApp().globalData;

export default {
  data() {
    return {
      id: "",
      company: "",
      index: -1,
      logNo: ""
    };
  },

  components: {},
  props: {},
  onLoad: function (options) {
    var id = options.id;
    this.setData({
      id
    });
    this.getCompany();
  },
  methods: {
    // 获取物流公司列表
    getCompany() {
      var that = this;
      getApp().globalData.sendRequest({
        url: "/Customer/LogisticsCompany",
        type: "post",
        data: {},
        success: function (res) {
          if (res.status == 1) {
            that.setData({
              company: res.express
            });
          } else {
            uni.showToast({
              title: res.msg,
              icon: 'none'
            });
          }
        }
      });
    },

    // 选择物流公司
    bindRegionChange(e) {
      console.log('bindRegionChange', e);
      var index = e.detail.value;
      this.setData({
        index: index
      });
    },

    // 提交
    commit() {
      var that = this;

      if (this.index == -1) {
        uni.showToast({
          title: "请选择物流公司",
          icon: 'none'
        });
        return;
      }
      if (!this.logNo) {
        uni.showToast({
          title: "请填入单号",
          icon: 'none'
        });
        return;
      }

      getApp().globalData.sendRequest({
        url: "/Customer/UserDeliverGoods",
        type: "post",
        data: {
          id: that.id,
          express_name: that.company[that.index].kd_name,
          express_code: that.company[that.index].kd_com,
          express_no: that.logNo
        },
        success: function (res) {
          if (res.status == 1) {
            uni.showToast({
              title: res.msg
            });
            setTimeout(() => {
              uni.navigateBack({}, 1000);
            });
          } else {
            uni.showToast({
              title: res.msg,
              icon: 'none'
            });
          }
        }
      });
    },

    inputNo(e) {
      var logNo = e.detail.value;
      this.setData({
        logNo
      });
    }

  }
};
</script>
<style>
@import "./serviceLogistic.css";
</style>